package org.mokusakura.web.controller;

import org.mokusakura.constant.ServletUrlConstant;
import org.mokusakura.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController

public class EmailAvailableController {
    public static final String RESPONSE_AVAILABLE = "true";
    public static final String RESPONSE_UNAVAILABLE = "false";
    public static final String EMAIL_TO_EXAM = "email";
    @Autowired
    private UserService userService;

    @GetMapping(ServletUrlConstant.EMAIL_AVAILABLE_SERVLET_URL)
    public Object isEmailAvailable(@RequestParam(EMAIL_TO_EXAM) String email) {
        return userService.getUserByEmail(email) == null ? RESPONSE_AVAILABLE : RESPONSE_UNAVAILABLE;
    }
}
